package admin.controller;

import admin.service.UserService;
import common.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/admin/user")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/add")
    public ResponseEntity<User> addUser(@RequestBody User user) {
        return ResponseEntity.ok(userService.addUser(user));
    }

    @DeleteMapping("/delete/{id}")
    public ResponseEntity<Void> deleteUser(@PathVariable Long id) {
        userService.deleteUser(id);
        return ResponseEntity.noContent().build();
    }

    @PutMapping("/update")
    public ResponseEntity<User> updateUser(@RequestBody User user) {
        return ResponseEntity.ok(userService.updateUser(user));
    }

    @GetMapping("/find")
    public ResponseEntity<List<User>> findUserByNickname(@RequestParam String nickname) {
        return ResponseEntity.ok(userService.findByNickname(nickname));
    }

    @PutMapping("/freeze/{id}")
    public ResponseEntity<Void> freezeUser(@PathVariable Long id) {
        userService.freezeUser(id);
        return ResponseEntity.noContent().build();
    }

    @PutMapping("/unfreeze/{id}")
    public ResponseEntity<Void> unfreezeUser(@PathVariable Long id) {
        userService.unfreezeUser(id);
        return ResponseEntity.noContent().build();
    }
}